﻿using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using TRPOP.Common;
using TRPOP.Config;

namespace TRPOP.CMS.Web.UI 
{
    public class ImagePage : BasePage
    {
        /// <summary>
        /// 输出验证码图片
        /// </summary>
        /// <param name="SessionName">Session名称</param>
        /// <param name="length">字符长度</param>
        protected void DrawImage(string SessionName, int length)
        {
            Response.Expires = -1;
            Response.ExpiresAbsolute = DateTime.Now.AddSeconds(-1);
            Response.CacheControl = "no-cache";

            string strRandom = Util.GetRandomCode(length);
            Session[SessionName] = strRandom;
            System.IO.MemoryStream ms = new System.IO.MemoryStream();
            ms = Util.IdentifyImg(strRandom, length, 20);
            Response.Clear();
            Response.ContentType = "image/jpeg";

            Response.BinaryWrite(ms.ToArray());
            Response.End();
        }
    }
}
